import Mock from 'mockjs'

const List = []
const count = 200

for (let i = 0; i < count; i++) {
  List.push(Mock.mock({
    id: i + 1,
    leave_code: Mock.Random.string(5),
    request_emp_name: Mock.Random.cname(),
    holiday_type: '',
    dept_name: Mock.Random.cname() + '部门',
    days: '@integer(1, 3)',
    start_date: Mock.Random.date(),
    end_date: Mock.Random.date(),
    contact_emp_name: Mock.Random.cname(),
    contact_phone: '',
    business_status: '',
    actual_end_date: Mock.Random.date(),
    leave_desc: '',
    creation_date: Mock.Random.date()
  }))
}

export default [
  {
    url: '/leaves',
    type: 'get',
    response: config => {
      const { page = 1, limit = 20, sort } = config.query

      let mockList = List

      if (sort === '-id') {
        mockList = mockList.reverse()
      }

      const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))

      return {
        code: 200,
        data: {
          total: mockList.length,
          items: pageList
        }
      }
    }
  }
]
